<?php

class LoginBox extends TE{

	public $templateFile = "LoginBox.tpl.html";
	public $templatePath = __DIR__ ;
	public $language = "es_ES" ;
	public $dictionaryFile = "I18n.txt" ;
	public $dictionaryPath = __DIR__ ; 
	public $title = "LoginBox";
	public $userFieldName = "username";
	public $passwordFieldName = "password";
	public $welcome="";
	public $error="";
	
	public function initialize(){
	
		$this->language = str_replace("-","_",substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5));
		if(strpos($_SERVER['HTTP_USER_AGENT'],"MSIE 6")){
			$this->browser="MSIE6";
			$this->templateFile="LoginBox.tpl.html";
		}
		if(strpos($_SERVER['HTTP_USER_AGENT'],"Chrome")){
			$this->browser="Chrome";
			$this->templateFile="CSSLoginBox.tpl.html";
		}
		if(strpos($_SERVER['HTTP_USER_AGENT'],"Firefox")){
			$this->browser="Firefox";
			$this->templateFile="CSSLoginBox.tpl.html";
		}
		
		
		//echo "<pre>";
		//print_r($_SERVER);
		//echo "</pre>";
	}
	
	
	public function show(){
		$this->welcome = $this->block;
		
		if(file_exists($this->templatePath."/".$this->templateFile)){
			$this->parse(file_get_contents($this->templatePath."/".$this->templateFile));
		}
		
		return $this->replace();
	}
	
	public function displayError($param,$block){
		if(isset($_POST['doLogin'])){
			$this->error = $block;
		}
		return "";
	} 
	
	public function translate($literal){
		if(!isset($this->dictionary)){
				$this->dictionary = parse_ini_file($this->dictionaryPath."/".$this->dictionaryFile, true,1);
		}
		$index = str_replace(" ","_",trim($literal));
		if(isset($this->dictionary[$this->language][$index])){
				return $this->dictionary[$this->language][$index];
		}
		
		return $literal;
	}
}

?>